class Solution {
public:
    int fac(int start, int end, vector<int>& nums)
    {
        int a = 0;
        int b = 0;
        int res = 0;
        for (int i = start; i <= end; i++)
        {
            res = max(b, a + nums[i]);
            a = b;
            b = res;
        }
        return res;
    }
    int rob(vector<int>& nums) {
        return max(nums[0] + fac(2, nums.size() - 2, nums), fac(1, nums.size() - 1, nums));
    }
};